package comparable_1102;


import java.util.Comparator;

public class Demo3 {
    static class 天干比较器 implements Comparator<Character> {
        @Override
        public int compare(Character o1, Character o2) {
            if (o1.equals('甲')) {
                if (o2.equals('甲')) {
                    return 0;
                } else {
                    // 认为 o2 是乙
                    return -1;
                }
            } else {
                // o1 是乙
                if (o2.equals('甲')) {
                    return 1;
                } else {
                    // o2 是乙
                    return 0;
                }
            }
        }
    }

    public static void main(String[] args) {
        // Character / char 是具备自然顺序的
        // 天干：甲 乙 丙 丁
        // 甲是小于乙
        // 不符合自然语义
        // 使用 Comparator 进行比较

        天干比较器 comparator = new 天干比较器();


        Character c1 = '甲';
        Character c2 = '乙';

        int cmp = comparator.compare(c1, c2);

        if (cmp < 0) {

            System.out.println(c1 + " 小于 " + c2);
        } else if (cmp == 0) {

            System.out.println(c1 + " 等于 " + c2);
        } else {

            System.out.println(c1 + " 大于 " + c2);
        }
    }

    public static void main2(String[] args) {
        Character c1 = '甲';
        Character c2 = '乙';

        int cmp = c1.compareTo(c2);
        if (cmp < 0) {

            System.out.println(c1 + " 小于 " + c2);
        } else if (cmp == 0) {

            System.out.println(c1 + " 等于 " + c2);
        } else {

            System.out.println(c1 + " 大于 " + c2);
        }
    }

    public static void main1(String[] args) {
        char c1 = '甲';
        char c2 = '乙';

        // 基本类型，可以用 大于号、小于号比较
        if (c1 < c2) {
            System.out.println(c1 + " 小于 " + c2);
        } else if (c1 == c2) {
            System.out.println(c1 + " 等于 " + c2);
        } else {
            System.out.println(c1 + " 大于 " + c2);
        }
    }
}
